package com.jinzhi.jzweb.controller;


import java.util.*;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazUserIntegralDO;
import com.jinzhi.jzweb.service.JazUserIntegralService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2023-04-18 10:00:53 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazUserIntegral")
public class JazUserIntegralController extends BaseController {
	@Autowired
	private JazUserIntegralService jazUserIntegralService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:jazUserIntegral:jazUserIntegral")
	String JazUserIntegral(){
	    return "jzweb/jazUserIntegral/jazUserIntegral";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:jazUserIntegral:jazUserIntegral")
	public Result<Page<JazUserIntegralDO>> list(JazUserIntegralDO jazUserIntegralDTO){
		// 查询列表数据
		Page<JazUserIntegralDO> page = jazUserIntegralService.selectPage(getPage(JazUserIntegralDO.class),
					jazUserIntegralService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				JazUserIntegralDO obj = (JazUserIntegralDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazUserIntegral:add")
	String add(){
	    return "jzweb/jazUserIntegral/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazUserIntegral:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazUserIntegralDO jazUserIntegral = jazUserIntegralService.selectById(id);
		model.addAttribute("jazUserIntegral", jazUserIntegral);
	    return "jzweb/jazUserIntegral/edit";
	}
	

	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazUserIntegral:add")
	public Result<String> save( JazUserIntegralDO jazUserIntegral){
		jazUserIntegralService.insert(jazUserIntegral);
        return Result.ok();
	}
	

	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazUserIntegral:edit")
	public Result<String>  update( JazUserIntegralDO jazUserIntegral){
		boolean update = jazUserIntegralService.updateById(jazUserIntegral);
		return update ? Result.ok() : Result.fail();
	}
	

	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazUserIntegral:remove")
	public Result<String>  remove( Long id){
		jazUserIntegralService.deleteById(id);
        return Result.ok();
	}
	

	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazUserIntegral:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazUserIntegralService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
